﻿using FyCacheClient;
using FySystem.FyAppConfig;
using FySystem.IO;
using System;

namespace FyCacheTest
{
    internal class Program
    {
        static void Main(string[] args)
        {


            ///账号和密码在服务端的configs.txt文件中配置，默认为admin和123456
            ///SCacheClient线程安全，一个项目理论上只创建一个实例
            var client = new SCacheClient("admin", "123456");

            //默认为0，总共10个，这行代码可以不写
            client.UseDb(0);

            //设置数据
            SetData(client);

            //读取数据
            ReadData(client);

            //获取服务端版本号
            GetVersion(client);

            Console.ReadKey();
        }

        private static void GetVersion(SCacheClient client)
        {
            string ver = client.GetServerVer();
            Console.WriteLine($"版本号：{ver}");
        }

        private static void ReadData(SCacheClient client)
        {
            var data = client.Get("aa");
            Console.WriteLine(data["name"].StringValue);
            Console.WriteLine(data["age"].IntValue);
        }

        private static void SetData(SCacheClient client)
        {
            CSon data = new CSon(CSon.CSonTypes.CObject);
            data.Add("name", "张三");
            data.Add("age", 30);

            client.Set("aa", data);
        }
    }
}
